package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/28 17:38
 * https://leetcode.cn/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
 */
public class Title54 {

    class TreeNode{
        int val;

        TreeNode left;

        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

    }

    int result;

    int count;

    public int kthLargest(TreeNode root, int k) {
        count = k;
        backTracking(root);
        return result;
    }

    private void backTracking(TreeNode root) {
        if (root == null) {
            return;
        }
        backTracking(root.right);
        count--;
        if (count == 0) {
            result = root.val;
        }
        backTracking(root.left);
    }

    public static void main(String[] args) {

    }
}
